package com.wipz.eoa.iphone.fixedassets;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.wipz.eoa.iphone.BaseAction;
import com.wipz.eoa.iphone.businessProcess.AgencyCoreService;
import com.wipz.eoa.iphone.businessProcess.TaskTransitionService;
import com.wipz.eoa.iphone.util.Constants;

/**
 * 
 * �̶��ʲ�ά��������
 *@version 1.0
 */

public class FixedAssetsRepairApplyAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private Map detail;
	private AgencyCoreService agencyCoreService;
	private IFixedAssetsRepairApplyService fixedAssetsRepairApplyService;
	private TaskTransitionService taskTransitionService;
	private Map bxSubmit;
	

	public Map getBxSubmit() {
		return bxSubmit;
	}

	public void setBxSubmit(Map bxSubmit) {
		this.bxSubmit = bxSubmit;
	}

	public void setTaskTransitionService(TaskTransitionService taskTransitionService) {
		this.taskTransitionService = taskTransitionService;
	}

	public void setFixedAssetsRepairApplyService(
			IFixedAssetsRepairApplyService fixedAssetsRepairApplyService) {
		this.fixedAssetsRepairApplyService = fixedAssetsRepairApplyService;
	}

	public void setAgencyCoreService(AgencyCoreService agencyCoreService) {
		this.agencyCoreService = agencyCoreService;
	}

	public Map getDetail() {
		return detail;
	}

	public void setDetail(Map detail) {
		this.detail = detail;
	}

	
	/**
	 * �鿴�̶��ʲ�ά������,���ID
	 * Function-�鿴:ID 
	 * @return
	 */
	public String detail() {
		String COMMITERCODE = this.getRequest().getParameter("COMMITERCODE");
		String taskId = this.getRequest().getParameter("taskId");
		String id = this.getRequest().getParameter("id");
		Map params = new HashMap();
		params.put("id",id);
		detail =  (Map) fixedAssetsRepairApplyService.queryOne("fixedAssets.queryOpID", params);
		
		Map newMap = (Map) fixedAssetsRepairApplyService.queryOne("businessProcess.queryByCode",detail);
		String processId = newMap == null ? "":(String)newMap.get("PROCESSID") ;
		detail.put("processInstanceId", processId);
		if(null == COMMITERCODE || COMMITERCODE.isEmpty()) {
			return SUCCESS;
		}
		String userId = (String) fixedAssetsRepairApplyService.queryOne("user.queryId",COMMITERCODE);
		detail = agencyCoreService.agencyList(Constants.ASSETSREPAIRAPPLY_BUSINESS_ID, userId,detail);	
		
		
		if(null == taskId || taskId.isEmpty()) {
			return SUCCESS;
		}
		
		detail.put("taskId", taskId);
		List list =(taskTransitionService.getTaskTransition(taskId));
		Map url = new HashMap();
		StringBuffer bf = new StringBuffer();
		bf.append("/fixedAssets/fixedAssetsRepair_bxSubmit.action?id=");
		bf.append(id);
		bf.append("&COMMITERCODE=");
		bf.append(COMMITERCODE);
		bf.append("&taskId=");
		bf.append(taskId);
		url.put("url", bf.toString());
		list.add(url);
		detail.put("button", list);
		return SUCCESS;
	}
	
	
	/**
	 * 审批
	 * @return
	 * 2012-2-21 下午02:53:46
	 */
	public String bxSubmit() {
		//获取ID
		String id = this.getRequest().getParameter("id");
		//用户代号
		String COMMITERCODE = this.getRequest().getParameter("COMMITERCODE");
		if(id.isEmpty() || COMMITERCODE.isEmpty()) {
			return SUCCESS;
		}
		//任务唯一标识taskId
		String taskId =  this.getRequest().getParameter("taskId");
		//处理意见
		String commentContent =  this.getRequest().getParameter("comment");
		try {
			String s = new String(commentContent.getBytes("iso-8859-1"),"utf-8");
			commentContent = java.net.URLDecoder.decode(s, "utf-8");
		} catch (UnsupportedEncodingException e) {
			return SUCCESS;
		}

		//流向
		String transition = this.getRequest().getParameter("name");
		//处理类型
		String typeaccept = this.getRequest().getParameter("pass");
		
		Map param = new HashMap();
		param.put("id",id );
		Map fixedAssetsMap =(Map)fixedAssetsRepairApplyService.queryOne("fixedAssets.queryOpID", param);
		Map processidMap =(Map)fixedAssetsRepairApplyService.queryOne("businessProcess.queryByCode",fixedAssetsMap);
		param.put("PROCESSID", processidMap.get("PROCESSID"));
		param.put("COMMITERCODE", COMMITERCODE);
		param.put("taskId",taskId );
		param.put("comment", commentContent);
		param.put("transition",transition );
		param.put("pass", typeaccept);
		Map mapUuid = (Map) fixedAssetsRepairApplyService.queryOne("user.queryAll", COMMITERCODE);
		param.put("uuitId",mapUuid.get("ORGID"));
		bxSubmit = fixedAssetsRepairApplyService.bxSubmit(param);
		return SUCCESS;
	}
}
